#ifndef E_CONTROLLER_QT_TREE_H
#define E_CONTROLLER_QT_TREE_H

#include "EItem.h"
#include "qtreewidget.h"
#include <DefineLibCommon.h>
#include <DefineCommon.h>
#include <memory>

#include <EController.h>
#include <QTreeWidget>


/**This class is
 * */
class EControllerQtTree;
typedef SmartPtr(EControllerQtTree) EControllerQtTreePtr;
class EControllerQtTree : public QObject, public EController
{
    Q_OBJECT
public:
    EControllerQtTree();
    virtual ~EControllerQtTree();

    void setTreeWidget(QTreeWidget* w);

    /*clear TreeWidget and loop all children and build Tree Item*/
    virtual void refresh();

    virtual EItemPtr addItem(EItemPtr typeItem);
    
    virtual EItemPtr copyItem(EItemPtr item);

    //delete item from getSelectedItem()
    virtual void deleteItem();

    EItemPtr getEItemByTreeItemPtr(QTreeWidgetItem* treeItem);

    QTreeWidgetItem* getTreeItemByEItemPtr(const EItemPtr& itemPtr);
    
    /*handle command*/
    virtual void handleCommand(const ECommandPtr& command);
    virtual void handleCommandRefresh(const ECommandPtr& command);
public slots:
    void slotCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);

protected:

    void buildConnect();
    void clearConnect();

    QTreeWidget* m_treeWidget;

};

#endif // E_CONTROLLER_QT_TREE_H


    // EControllerTreeItem* newTreeItemByEItemPtr(const EItemPtr& itemPtr);
    // void synTreeItemAndEItem(const EItemPtr& itemPtr, EControllerTreeItem* treeItem);
    // int checkItemTypeCount(const EString& className);
    /*overwrite EItemVisitor's core function*/
    // virtual bool handleEItem(EItemPtr item, int depth, EItemPtr parentItem);
    /*overwrite EController's function, to return a selected EItemPtr*/
    // virtual EItemPtr getSelectedItem();

    //set selected item by outer
    // void setSelectedItem(EItemPtr item);

    // void addItem_deprected(long tagTypeItem);
    // virtual void deleteItem(long tag);
    // QMap<long, EControllerTreeItem*> m_mapTag2TreeItem;
    // QMap<long, EItemPtr> m_mapTag2EItem;
    // EItemPtr m_selectedEItem;
    // virtual void copyItem(long tag);

    // virtual void selectItem(EItemPtr item);
    // virtual void disSelectItem(EItemPtr item);
